home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Programming / gcc-2.95.3-3 / info / g77.info-14 < prev    next >
Encoding:
GNU Info File  |  2001-07-15  |  49.7 KB  |  1,181 lines

  1. This is Info file f/g77.info, produced by Makeinfo version 1.68 from
  2. the input file ./f/g77.texi.
  3.  
  4. INFO-DIR-SECTION Programming
  5. START-INFO-DIR-ENTRY
  6. * g77: (g77).                  The GNU Fortran compiler.
  7. END-INFO-DIR-ENTRY
  8.    This file documents the use and the internals of the GNU Fortran
  9. (`g77') compiler.  It corresponds to the GCC-2.95 version of `g77'.
  10.  
  11.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  12. Boston, MA 02111-1307 USA
  13.  
  14.    Copyright (C) 1995-1999 Free Software Foundation, Inc.
  15.  
  16.    Permission is granted to make and distribute verbatim copies of this
  17. manual provided the copyright notice and this permission notice are
  18. preserved on all copies.
  19.  
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the sections entitled "GNU General Public License," "Funding for
  23. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  24. included exactly as in the original, and provided that the entire
  25. resulting derived work is distributed under the terms of a permission
  26. notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that the sections entitled "GNU General Public
  31. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  32. `Look And Feel'", and this permission notice, may be included in
  33. translations approved by the Free Software Foundation instead of in the
  34. original English.
  35.  
  36.    Contributed by James Craig Burley (<craig@jcb-sc.com>).  Inspired by
  37. a first pass at translating `g77-0.5.16/f/DOC' that was contributed to
  38. Craig by David Ronis (<ronis@onsager.chem.mcgill.ca>).
  39.  
  40. 
  41. File: g77.info,  Node: Common Blocks,  Next: Local Equivalence Areas,  Prev: Names,  Up: Debugging and Interfacing
  42.  
  43. Common Blocks (COMMON)
  44. ======================
  45.  
  46.    `g77' names and lays out `COMMON' areas the same way `f2c' does, for
  47. compatibility with `f2c'.
  48.  
  49.    Currently, `g77' does not emit "true" debugging information for
  50. members of a `COMMON' area, due to an apparent bug in the GBE.
  51.  
  52.    (As of Version 0.5.19, `g77' emits debugging information for such
  53. members in the form of a constant string specifying the base name of
  54. the aggregate area and the offset of the member in bytes from the start
  55. of the area.  Use the `-fdebug-kludge' option to enable this behavior.
  56. In `gdb', use `set language c' before printing the value of the member,
  57. then `set language fortran' to restore the default language, since
  58. `gdb' doesn't provide a way to print a readable version of a character
  59. string in Fortran language mode.
  60.  
  61.    This kludge will be removed in a future version of `g77' that, in
  62. conjunction with a contemporary version of `gdb', properly supports
  63. Fortran-language debugging, including access to members of `COMMON'
  64. areas.)
  65.  
  66.    *Note Options for Code Generation Conventions: Code Gen Options, for
  67. information on the `-fdebug-kludge' option.
  68.  
  69.    Moreover, `g77' currently implements a `COMMON' area such that its
  70. type is an array of the C `char' data type.
  71.  
  72.    So, when debugging, you must know the offset into a `COMMON' area
  73. for a particular item in that area, and you have to take into account
  74. the appropriate multiplier for the respective sizes of the types (as
  75. declared in your code) for the items preceding the item in question as
  76. compared to the size of the `char' type.
  77.  
  78.    For example, using default implicit typing, the statement
  79.  
  80.      COMMON I(15), R(20), T
  81.  
  82. results in a public 144-byte `char' array named `_BLNK__' with `I'
  83. placed at `_BLNK__[0]', `R' at `_BLNK__[60]', and `T' at `_BLNK__[140]'.
  84. (This is assuming that the target machine for the compilation has
  85. 4-byte `INTEGER(KIND=1)' and `REAL(KIND=1)' types.)
  86.  
  87. 
  88. File: g77.info,  Node: Local Equivalence Areas,  Next: Complex Variables,  Prev: Common Blocks,  Up: Debugging and Interfacing
  89.  
  90. Local Equivalence Areas (EQUIVALENCE)
  91. =====================================
  92.  
  93.    `g77' treats storage-associated areas involving a `COMMON' block as
  94. explained in the section on common blocks.
  95.  
  96.    A local `EQUIVALENCE' area is a collection of variables and arrays
  97. connected to each other in any way via `EQUIVALENCE', none of which are
  98. listed in a `COMMON' statement.
  99.  
  100.    Currently, `g77' does not emit "true" debugging information for
  101. members in a local `EQUIVALENCE' area, due to an apparent bug in the
  102. GBE.
  103.  
  104.    (As of Version 0.5.19, `g77' does emit debugging information for such
  105. members in the form of a constant string specifying the base name of
  106. the aggregate area and the offset of the member in bytes from the start
  107. of the area.  Use the `-fdebug-kludge' option to enable this behavior.
  108. In `gdb', use `set language c' before printing the value of the member,
  109. then `set language fortran' to restore the default language, since
  110. `gdb' doesn't provide a way to print a readable version of a character
  111. string in Fortran language mode.
  112.  
  113.    This kludge will be removed in a future version of `g77' that, in
  114. conjunction with a contemporary version of `gdb', properly supports
  115. Fortran-language debugging, including access to members of
  116. `EQUIVALENCE' areas.)
  117.  
  118.    *Note Options for Code Generation Conventions: Code Gen Options, for
  119. information on the `-fdebug-kludge' option.
  120.  
  121.    Moreover, `g77' implements a local `EQUIVALENCE' area such that its
  122. type is an array of the C `char' data type.
  123.  
  124.    The name `g77' gives this array of `char' type is `__g77_equiv_X',
  125. where X is the name of the item that is placed at the beginning (offset
  126. 0) of this array.  If more than one such item is placed at the
  127. beginning, X is the name that sorts to the top in an alphabetical sort
  128. of the list of such items.
  129.  
  130.    When debugging, you must therefore access members of `EQUIVALENCE'
  131. areas by specifying the appropriate `__g77_equiv_X' array section with
  132. the appropriate offset.  See the explanation of debugging `COMMON'
  133. blocks for info applicable to debugging local `EQUIVALENCE' areas.
  134.  
  135.    (*Note:* `g77' version 0.5.18 and earlier chose the name for X using
  136. a different method when more than one name was in the list of names of
  137. entities placed at the beginning of the array.  Though the
  138. documentation specified that the first name listed in the `EQUIVALENCE'
  139. statements was chosen for X, `g77' in fact chose the name using a
  140. method that was so complicated, it seemed easier to change it to an
  141. alphabetical sort than to describe the previous method in the
  142. documentation.)
  143.  
  144. 
  145. File: g77.info,  Node: Complex Variables,  Next: Arrays,  Prev: Local Equivalence Areas,  Up: Debugging and Interfacing
  146.  
  147. Complex Variables (COMPLEX)
  148. ===========================
  149.  
  150.    As of 0.5.20, `g77' defaults to handling `COMPLEX' types (and
  151. related intrinsics, constants, functions, and so on) in a manner that
  152. makes direct debugging involving these types in Fortran language mode
  153. difficult.
  154.  
  155.    Essentially, `g77' implements these types using an internal
  156. construct similar to C's `struct', at least as seen by the `gcc' back
  157. end.
  158.  
  159.    Currently, the back end, when outputting debugging info with the
  160. compiled code for the assembler to digest, does not detect these
  161. `struct' types as being substitutes for Fortran complex.  As a result,
  162. the Fortran language modes of debuggers such as `gdb' see these types
  163. as C `struct' types, which they might or might not support.
  164.  
  165.    Until this is fixed, switch to C language mode to work with entities
  166. of `COMPLEX' type and then switch back to Fortran language mode
  167. afterward.  (In `gdb', this is accomplished via `set lang c' and either
  168. `set lang fortran' or `set lang auto'.)
  169.  
  170. 
  171. File: g77.info,  Node: Arrays,  Next: Adjustable Arrays,  Prev: Complex Variables,  Up: Debugging and Interfacing
  172.  
  173. Arrays (DIMENSION)
  174. ==================
  175.  
  176.    Fortran uses "column-major ordering" in its arrays.  This differs
  177. from other languages, such as C, which use "row-major ordering".  The
  178. difference is that, with Fortran, array elements adjacent to each other
  179. in memory differ in the *first* subscript instead of the last;
  180. `A(5,10,20)' immediately follows `A(4,10,20)', whereas with row-major
  181. ordering it would follow `A(5,10,19)'.
  182.  
  183.    This consideration affects not only interfacing with and debugging
  184. Fortran code, it can greatly affect how code is designed and written,
  185. especially when code speed and size is a concern.
  186.  
  187.    Fortran also differs from C, a popular language for interfacing and
  188. to support directly in debuggers, in the way arrays are treated.  In C,
  189. arrays are single-dimensional and have interesting relationships to
  190. pointers, neither of which is true for Fortran.  As a result, dealing
  191. with Fortran arrays from within an environment limited to C concepts
  192. can be challenging.
  193.  
  194.    For example, accessing the array element `A(5,10,20)' is easy enough
  195. in Fortran (use `A(5,10,20)'), but in C some difficult machinations are
  196. needed.  First, C would treat the A array as a single-dimension array.
  197. Second, C does not understand low bounds for arrays as does Fortran.
  198. Third, C assumes a low bound of zero (0), while Fortran defaults to a
  199. low bound of one (1) and can supports an arbitrary low bound.
  200. Therefore, calculations must be done to determine what the C equivalent
  201. of `A(5,10,20)' would be, and these calculations require knowing the
  202. dimensions of `A'.
  203.  
  204.    For `DIMENSION A(2:11,21,0:29)', the calculation of the offset of
  205. `A(5,10,20)' would be:
  206.  
  207.        (5-2)
  208.      + (10-1)*(11-2+1)
  209.      + (20-0)*(11-2+1)*(21-1+1)
  210.      = 4293
  211.  
  212. So the C equivalent in this case would be `a[4293]'.
  213.  
  214.    When using a debugger directly on Fortran code, the C equivalent
  215. might not work, because some debuggers cannot understand the notion of
  216. low bounds other than zero.  However, unlike `f2c', `g77' does inform
  217. the GBE that a multi-dimensional array (like `A' in the above example)
  218. is really multi-dimensional, rather than a single-dimensional array, so
  219. at least the dimensionality of the array is preserved.
  220.  
  221.    Debuggers that understand Fortran should have no trouble with
  222. non-zero low bounds, but for non-Fortran debuggers, especially C
  223. debuggers, the above example might have a C equivalent of `a[4305]'.
  224. This calculation is arrived at by eliminating the subtraction of the
  225. lower bound in the first parenthesized expression on each line--that
  226. is, for `(5-2)' substitute `(5)', for `(10-1)' substitute `(10)', and
  227. for `(20-0)' substitute `(20)'.  Actually, the implication of this can
  228. be that the expression `*(&a[2][1][0] + 4293)' works fine, but that
  229. `a[20][10][5]' produces the equivalent of `*(&a[0][0][0] + 4305)'
  230. because of the missing lower bounds.
  231.  
  232.    Come to think of it, perhaps the behavior is due to the debugger
  233. internally compensating for the lower bounds by offsetting the base
  234. address of `a', leaving `&a' set lower, in this case, than
  235. `&a[2][1][0]' (the address of its first element as identified by
  236. subscripts equal to the corresponding lower bounds).
  237.  
  238.    You know, maybe nobody really needs to use arrays.
  239.  
  240. 
  241. File: g77.info,  Node: Adjustable Arrays,  Next: Alternate Entry Points,  Prev: Arrays,  Up: Debugging and Interfacing
  242.  
  243. Adjustable Arrays (DIMENSION)
  244. =============================
  245.  
  246.    Adjustable and automatic arrays in Fortran require the implementation
  247. (in this case, the `g77' compiler) to "memorize" the expressions that
  248. dimension the arrays each time the procedure is invoked.  This is so
  249. that subsequent changes to variables used in those expressions, made
  250. during execution of the procedure, do not have any effect on the
  251. dimensions of those arrays.
  252.  
  253.    For example:
  254.  
  255.      REAL ARRAY(5)
  256.      DATA ARRAY/5*2/
  257.      CALL X(ARRAY, 5)
  258.      END
  259.      SUBROUTINE X(A, N)
  260.      DIMENSION A(N)
  261.      N = 20
  262.      PRINT *, N, A
  263.      END
  264.  
  265. Here, the implementation should, when running the program, print
  266. something like:
  267.  
  268.      20   2.  2.  2.  2.  2.
  269.  
  270. Note that this shows that while the value of `N' was successfully
  271. changed, the size of the `A' array remained at 5 elements.
  272.  
  273.    To support this, `g77' generates code that executes before any user
  274. code (and before the internally generated computed `GOTO' to handle
  275. alternate entry points, as described below) that evaluates each
  276. (nonconstant) expression in the list of subscripts for an array, and
  277. saves the result of each such evaluation to be used when determining
  278. the size of the array (instead of re-evaluating the expressions).
  279.  
  280.    So, in the above example, when `X' is first invoked, code is
  281. executed that copies the value of `N' to a temporary.  And that same
  282. temporary serves as the actual high bound for the single dimension of
  283. the `A' array (the low bound being the constant 1).  Since the user
  284. program cannot (legitimately) change the value of the temporary during
  285. execution of the procedure, the size of the array remains constant
  286. during each invocation.
  287.  
  288.    For alternate entry points, the code `g77' generates takes into
  289. account the possibility that a dummy adjustable array is not actually
  290. passed to the actual entry point being invoked at that time.  In that
  291. case, the public procedure implementing the entry point passes to the
  292. master private procedure implementing all the code for the entry points
  293. a `NULL' pointer where a pointer to that adjustable array would be
  294. expected.  The `g77'-generated code doesn't attempt to evaluate any of
  295. the expressions in the subscripts for an array if the pointer to that
  296. array is `NULL' at run time in such cases.  (Don't depend on this
  297. particular implementation by writing code that purposely passes `NULL'
  298. pointers where the callee expects adjustable arrays, even if you know
  299. the callee won't reference the arrays--nor should you pass `NULL'
  300. pointers for any dummy arguments used in calculating the bounds of such
  301. arrays or leave undefined any values used for that purpose in
  302. COMMON--because the way `g77' implements these things might change in
  303. the future!)
  304.  
  305. 
  306. File: g77.info,  Node: Alternate Entry Points,  Next: Alternate Returns,  Prev: Adjustable Arrays,  Up: Debugging and Interfacing
  307.  
  308. Alternate Entry Points (ENTRY)
  309. ==============================
  310.  
  311.    The GBE does not understand the general concept of alternate entry
  312. points as Fortran provides via the ENTRY statement.  `g77' gets around
  313. this by using an approach to compiling procedures having at least one
  314. `ENTRY' statement that is almost identical to the approach used by
  315. `f2c'.  (An alternate approach could be used that would probably
  316. generate faster, but larger, code that would also be a bit easier to
  317. debug.)
  318.  
  319.    Information on how `g77' implements `ENTRY' is provided for those
  320. trying to debug such code.  The choice of implementation seems unlikely
  321. to affect code (compiled in other languages) that interfaces to such
  322. code.
  323.  
  324.    `g77' compiles exactly one public procedure for the primary entry
  325. point of a procedure plus each `ENTRY' point it specifies, as usual.
  326. That is, in terms of the public interface, there is no difference
  327. between
  328.  
  329.      SUBROUTINE X
  330.      END
  331.      SUBROUTINE Y
  332.      END
  333.  
  334. and:
  335.  
  336.      SUBROUTINE X
  337.      ENTRY Y
  338.      END
  339.  
  340.    The difference between the above two cases lies in the code compiled
  341. for the `X' and `Y' procedures themselves, plus the fact that, for the
  342. second case, an extra internal procedure is compiled.
  343.  
  344.    For every Fortran procedure with at least one `ENTRY' statement,
  345. `g77' compiles an extra procedure named `__g77_masterfun_X', where X is
  346. the name of the primary entry point (which, in the above case, using
  347. the standard compiler options, would be `x_' in C).
  348.  
  349.    This extra procedure is compiled as a private procedure--that is, a
  350. procedure not accessible by name to separately compiled modules.  It
  351. contains all the code in the program unit, including the code for the
  352. primary entry point plus for every entry point.  (The code for each
  353. public procedure is quite short, and explained later.)
  354.  
  355.    The extra procedure has some other interesting characteristics.
  356.  
  357.    The argument list for this procedure is invented by `g77'.  It
  358. contains a single integer argument named `__g77_which_entrypoint',
  359. passed by value (as in Fortran's `%VAL()' intrinsic), specifying the
  360. entry point index--0 for the primary entry point, 1 for the first entry
  361. point (the first `ENTRY' statement encountered), 2 for the second entry
  362. point, and so on.
  363.  
  364.    It also contains, for functions returning `CHARACTER' and (when
  365. `-ff2c' is in effect) `COMPLEX' functions, and for functions returning
  366. different types among the `ENTRY' statements (e.g. `REAL FUNCTION R()'
  367. containing `ENTRY I()'), an argument named `__g77_result' that is
  368. expected at run time to contain a pointer to where to store the result
  369. of the entry point.  For `CHARACTER' functions, this storage area is an
  370. array of the appropriate number of characters; for `COMPLEX' functions,
  371. it is the appropriate area for the return type; for
  372. multiple-return-type functions, it is a union of all the supported
  373. return types (which cannot include `CHARACTER', since combining
  374. `CHARACTER' and non-`CHARACTER' return types via `ENTRY' in a single
  375. function is not supported by `g77').
  376.  
  377.    For `CHARACTER' functions, the `__g77_result' argument is followed
  378. by yet another argument named `__g77_length' that, at run time,
  379. specifies the caller's expected length of the returned value.  Note
  380. that only `CHARACTER*(*)' functions and entry points actually make use
  381. of this argument, even though it is always passed by all callers of
  382. public `CHARACTER' functions (since the caller does not generally know
  383. whether such a function is `CHARACTER*(*)' or whether there are any
  384. other callers that don't have that information).
  385.  
  386.    The rest of the argument list is the union of all the arguments
  387. specified for all the entry points (in their usual forms, e.g.
  388. `CHARACTER' arguments have extra length arguments, all appended at the
  389. end of this list).  This is considered the "master list" of arguments.
  390.  
  391.    The code for this procedure has, before the code for the first
  392. executable statement, code much like that for the following Fortran
  393. statement:
  394.  
  395.             GOTO (100000,100001,100002), __g77_which_entrypoint
  396.      100000 ...code for primary entry point...
  397.      100001 ...code immediately following first ENTRY statement...
  398.      100002 ...code immediately following second ENTRY statement...
  399.  
  400. (Note that invalid Fortran statement labels and variable names are used
  401. in the above example to highlight the fact that it represents code
  402. generated by the `g77' internals, not code to be written by the user.)
  403.  
  404.    It is this code that, when the procedure is called, picks which
  405. entry point to start executing.
  406.  
  407.    Getting back to the public procedures (`x' and `Y' in the original
  408. example), those procedures are fairly simple.  Their interfaces are
  409. just like they would be if they were self-contained procedures (without
  410. `ENTRY'), of course, since that is what the callers expect.  Their code
  411. consists of simply calling the private procedure, described above, with
  412. the appropriate extra arguments (the entry point index, and perhaps a
  413. pointer to a multiple-type- return variable, local to the public
  414. procedure, that contains all the supported returnable non-character
  415. types).  For arguments that are not listed for a given entry point that
  416. are listed for other entry points, and therefore that are in the
  417. "master list" for the private procedure, null pointers (in C, the
  418. `NULL' macro) are passed.  Also, for entry points that are part of a
  419. multiple-type- returning function, code is compiled after the call of
  420. the private procedure to extract from the multi-type union the
  421. appropriate result, depending on the type of the entry point in
  422. question, returning that result to the original caller.
  423.  
  424.    When debugging a procedure containing alternate entry points, you
  425. can either set a break point on the public procedure itself (e.g.  a
  426. break point on `X' or `Y') or on the private procedure that contains
  427. most of the pertinent code (e.g. `__g77_masterfun_X').  If you do the
  428. former, you should use the debugger's command to "step into" the called
  429. procedure to get to the actual code; with the latter approach, the
  430. break point leaves you right at the actual code, skipping over the
  431. public entry point and its call to the private procedure (unless you
  432. have set a break point there as well, of course).
  433.  
  434.    Further, the list of dummy arguments that is visible when the
  435. private procedure is active is going to be the expanded version of the
  436. list for whichever particular entry point is active, as explained
  437. above, and the way in which return values are handled might well be
  438. different from how they would be handled for an equivalent single-entry
  439. function.
  440.  
  441. 
  442. File: g77.info,  Node: Alternate Returns,  Next: Assigned Statement Labels,  Prev: Alternate Entry Points,  Up: Debugging and Interfacing
  443.  
  444. Alternate Returns (SUBROUTINE and RETURN)
  445. =========================================
  446.  
  447.    Subroutines with alternate returns (e.g. `SUBROUTINE X(*)' and `CALL
  448. X(*50)') are implemented by `g77' as functions returning the C `int'
  449. type.  The actual alternate-return arguments are omitted from the
  450. calling sequence.  Instead, the caller uses the return value to do a
  451. rough equivalent of the Fortran computed-`GOTO' statement, as in `GOTO
  452. (50), X()' in the example above (where `X' is quietly declared as an
  453. `INTEGER(KIND=1)' function), and the callee just returns whatever
  454. integer is specified in the `RETURN' statement for the subroutine For
  455. example, `RETURN 1' is implemented as `X = 1' followed by `RETURN' in
  456. C, and `RETURN' by itself is `X = 0' and `RETURN').
  457.  
  458. 
  459. File: g77.info,  Node: Assigned Statement Labels,  Next: Run-time Library Errors,  Prev: Alternate Returns,  Up: Debugging and Interfacing
  460.  
  461. Assigned Statement Labels (ASSIGN and GOTO)
  462. ===========================================
  463.  
  464.    For portability to machines where a pointer (such as to a label,
  465. which is how `g77' implements `ASSIGN' and its relatives, the
  466. assigned-`GOTO' and assigned-`FORMAT'-I/O statements) is wider
  467. (bitwise) than an `INTEGER(KIND=1)', `g77' uses a different memory
  468. location to hold the `ASSIGN'ed value of a variable than it does the
  469. numerical value in that variable, unless the variable is wide enough
  470. (can hold enough bits).
  471.  
  472.    In particular, while `g77' implements
  473.  
  474.      I = 10
  475.  
  476. as, in C notation, `i = 10;', it implements
  477.  
  478.      ASSIGN 10 TO I
  479.  
  480. as, in GNU's extended C notation (for the label syntax),
  481. `__g77_ASSIGN_I = &&L10;' (where `L10' is just a massaging of the
  482. Fortran label `10' to make the syntax C-like; `g77' doesn't actually
  483. generate the name `L10' or any other name like that, since debuggers
  484. cannot access labels anyway).
  485.  
  486.    While this currently means that an `ASSIGN' statement does not
  487. overwrite the numeric contents of its target variable, *do not* write
  488. any code depending on this feature.  `g77' has already changed this
  489. implementation across versions and might do so in the future.  This
  490. information is provided only to make debugging Fortran programs
  491. compiled with the current version of `g77' somewhat easier.  If there's
  492. no debugger-visible variable named `__g77_ASSIGN_I' in a program unit
  493. that does `ASSIGN 10 TO I', that probably means `g77' has decided it
  494. can store the pointer to the label directly into `I' itself.
  495.  
  496.    *Note Ugly Assigned Labels::, for information on a command-line
  497. option to force `g77' to use the same storage for both normal and
  498. assigned-label uses of a variable.
  499.  
  500. 
  501. File: g77.info,  Node: Run-time Library Errors,  Prev: Assigned Statement Labels,  Up: Debugging and Interfacing
  502.  
  503. Run-time Library Errors
  504. =======================
  505.  
  506.    The `libg2c' library currently has the following table to relate
  507. error code numbers, returned in `IOSTAT=' variables, to messages.  This
  508. information should, in future versions of this document, be expanded
  509. upon to include detailed descriptions of each message.
  510.  
  511.    In line with good coding practices, any of the numbers in the list
  512. below should *not* be directly written into Fortran code you write.
  513. Instead, make a separate `INCLUDE' file that defines `PARAMETER' names
  514. for them, and use those in your code, so you can more easily change the
  515. actual numbers in the future.
  516.  
  517.    The information below is culled from the definition of `F_err' in
  518. `f/runtime/libI77/err.c' in the `g77' source tree.
  519.  
  520.      100: "error in format"
  521.      101: "illegal unit number"
  522.      102: "formatted io not allowed"
  523.      103: "unformatted io not allowed"
  524.      104: "direct io not allowed"
  525.      105: "sequential io not allowed"
  526.      106: "can't backspace file"
  527.      107: "null file name"
  528.      108: "can't stat file"
  529.      109: "unit not connected"
  530.      110: "off end of record"
  531.      111: "truncation failed in endfile"
  532.      112: "incomprehensible list input"
  533.      113: "out of free space"
  534.      114: "unit not connected"
  535.      115: "read unexpected character"
  536.      116: "bad logical input field"
  537.      117: "bad variable type"
  538.      118: "bad namelist name"
  539.      119: "variable not in namelist"
  540.      120: "no end record"
  541.      121: "variable count incorrect"
  542.      122: "subscript for scalar variable"
  543.      123: "invalid array section"
  544.      124: "substring out of bounds"
  545.      125: "subscript out of bounds"
  546.      126: "can't read file"
  547.      127: "can't write file"
  548.      128: "'new' file exists"
  549.      129: "can't append to file"
  550.      130: "non-positive record number"
  551.      131: "I/O started while already doing I/O"
  552.  
  553. 
  554. File: g77.info,  Node: Collected Fortran Wisdom,  Next: Trouble,  Prev: Debugging and Interfacing,  Up: Top
  555.  
  556. Collected Fortran Wisdom
  557. ************************
  558.  
  559.    Most users of `g77' can be divided into two camps:
  560.  
  561.    * Those writing new Fortran code to be compiled by `g77'.
  562.  
  563.    * Those using `g77' to compile existing, "legacy" code.
  564.  
  565.    Users writing new code generally understand most of the necessary
  566. aspects of Fortran to write "mainstream" code, but often need help
  567. deciding how to handle problems, such as the construction of libraries
  568. containing `BLOCK DATA'.
  569.  
  570.    Users dealing with "legacy" code sometimes don't have much
  571. experience with Fortran, but believe that the code they're compiling
  572. already works when compiled by other compilers (and might not
  573. understand why, as is sometimes the case, it doesn't work when compiled
  574. by `g77').
  575.  
  576.    The following information is designed to help users do a better job
  577. coping with existing, "legacy" Fortran code, and with writing new code
  578. as well.
  579.  
  580. * Menu:
  581.  
  582. * Advantages Over f2c::        If `f2c' is so great, why `g77'?
  583. * Block Data and Libraries::   How `g77' solves a common problem.
  584. * Loops::                      Fortran `DO' loops surprise many people.
  585. * Working Programs::           Getting programs to work should be done first.
  586. * Overly Convenient Options::  Temptations to avoid, habits to not form.
  587. * Faster Programs::            Everybody wants these, but at what cost?
  588.  
  589. 
  590. File: g77.info,  Node: Advantages Over f2c,  Next: Block Data and Libraries,  Up: Collected Fortran Wisdom
  591.  
  592. Advantages Over f2c
  593. ===================
  594.  
  595.    Without `f2c', `g77' would have taken much longer to do and probably
  596. not been as good for quite a while.  Sometimes people who notice how
  597. much `g77' depends on, and documents encouragement to use, `f2c' ask
  598. why `g77' was created if `f2c' already existed.
  599.  
  600.    This section gives some basic answers to these questions, though it
  601. is not intended to be comprehensive.
  602.  
  603. * Menu:
  604.  
  605. * Language Extensions::  Features used by Fortran code.
  606. * Diagnostic Abilities:: Abilities to spot problems early.
  607. * Compiler Options::     Features helpful to accommodate legacy code, etc.
  608. * Compiler Speed::       Speed of the compilation process.
  609. * Program Speed::        Speed of the generated, optimized code.
  610. * Ease of Debugging::    Debugging ease-of-use at the source level.
  611. * Character and Hollerith Constants::  A byte saved is a byte earned.
  612.  
  613. 
  614. File: g77.info,  Node: Language Extensions,  Next: Diagnostic Abilities,  Up: Advantages Over f2c
  615.  
  616. Language Extensions
  617. -------------------
  618.  
  619.    `g77' offers several extensions to FORTRAN 77 language that `f2c'
  620. doesn't:
  621.  
  622.    * Automatic arrays
  623.  
  624.    * `CYCLE' and `EXIT'
  625.  
  626.    * Construct names
  627.  
  628.    * `SELECT CASE'
  629.  
  630.    * `KIND=' and `LEN=' notation
  631.  
  632.    * Semicolon as statement separator
  633.  
  634.    * Constant expressions in `FORMAT' statements (such as
  635.      `FORMAT(I<J>)', where `J' is a `PARAMETER' named constant)
  636.  
  637.    * `MvBits' intrinsic
  638.  
  639.    * `libU77' (Unix-compatibility) library, with routines known to
  640.      compiler as intrinsics (so they work even when compiler options
  641.      are used to change the interfaces used by Fortran routines)
  642.  
  643.    `g77' also implements iterative `DO' loops so that they work even in
  644. the presence of certain "extreme" inputs, unlike `f2c'.  *Note Loops::.
  645.  
  646.    However, `f2c' offers a few that `g77' doesn't, such as:
  647.  
  648.    * Intrinsics in `PARAMETER' statements
  649.  
  650.    * Array bounds expressions (such as `REAL M(N(2))')
  651.  
  652.    * `AUTOMATIC' statement
  653.  
  654.    It is expected that `g77' will offer some or all of these missing
  655. features at some time in the future.
  656.  
  657. 
  658. File: g77.info,  Node: Diagnostic Abilities,  Next: Compiler Options,  Prev: Language Extensions,  Up: Advantages Over f2c
  659.  
  660. Diagnostic Abilities
  661. --------------------
  662.  
  663.    `g77' offers better diagnosis of problems in `FORMAT' statements.
  664. `f2c' doesn't, for example, emit any diagnostic for
  665. `FORMAT(XZFAJG10324)', leaving that to be diagnosed, at run time, by
  666. the `libf2c' run-time library.
  667.  
  668. 
  669. File: g77.info,  Node: Compiler Options,  Next: Compiler Speed,  Prev: Diagnostic Abilities,  Up: Advantages Over f2c
  670.  
  671. Compiler Options
  672. ----------------
  673.  
  674.    `g77' offers compiler options that `f2c' doesn't, most of which are
  675. designed to more easily accommodate legacy code:
  676.  
  677.    * Two that control the automatic appending of extra underscores to
  678.      external names
  679.  
  680.    * One that allows dollar signs (`$') in symbol names
  681.  
  682.    * A variety that control acceptance of various "ugly" constructs
  683.  
  684.    * Several that specify acceptable use of upper and lower case in the
  685.      source code
  686.  
  687.    * Many that enable, disable, delete, or hide groups of intrinsics
  688.  
  689.    * One to specify the length of fixed-form source lines (normally 72)
  690.  
  691.    * One to specify the the source code is written in Fortran-90-style
  692.      free-form
  693.  
  694.    However, `f2c' offers a few that `g77' doesn't, like an option to
  695. have `REAL' default to `REAL*8'.  It is expected that `g77' will offer
  696. all of the missing options pertinent to being a Fortran compiler at
  697. some time in the future.
  698.  
  699. 
  700. File: g77.info,  Node: Compiler Speed,  Next: Program Speed,  Prev: Compiler Options,  Up: Advantages Over f2c
  701.  
  702. Compiler Speed
  703. --------------
  704.  
  705.    Saving the steps of writing and then rereading C code is a big reason
  706. why `g77' should be able to compile code much faster than using `f2c'
  707. in conjunction with the equivalent invocation of `gcc'.
  708.  
  709.    However, due to `g77''s youth, lots of self-checking is still being
  710. performed.  As a result, this improvement is as yet unrealized (though
  711. the potential seems to be there for quite a big speedup in the future).
  712. It is possible that, as of version 0.5.18, `g77' is noticeably faster
  713. compiling many Fortran source files than using `f2c' in conjunction
  714. with `gcc'.
  715.  
  716. 
  717. File: g77.info,  Node: Program Speed,  Next: Ease of Debugging,  Prev: Compiler Speed,  Up: Advantages Over f2c
  718.  
  719. Program Speed
  720. -------------
  721.  
  722.    `g77' has the potential to better optimize code than `f2c', even
  723. when `gcc' is used to compile the output of `f2c', because `f2c' must
  724. necessarily translate Fortran into a somewhat lower-level language (C)
  725. that cannot preserve all the information that is potentially useful for
  726. optimization, while `g77' can gather, preserve, and transmit that
  727. information directly to the GBE.
  728.  
  729.    For example, `g77' implements `ASSIGN' and assigned `GOTO' using
  730. direct assignment of pointers to labels and direct jumps to labels,
  731. whereas `f2c' maps the assigned labels to integer values and then uses
  732. a C `switch' statement to encode the assigned `GOTO' statements.
  733.  
  734.    However, as is typical, theory and reality don't quite match, at
  735. least not in all cases, so it is still the case that `f2c' plus `gcc'
  736. can generate code that is faster than `g77'.
  737.  
  738.    Version 0.5.18 of `g77' offered default settings and options, via
  739. patches to the `gcc' back end, that allow for better program speed,
  740. though some of these improvements also affected the performance of
  741. programs translated by `f2c' and then compiled by `g77''s version of
  742. `gcc'.
  743.  
  744.    Version 0.5.20 of `g77' offers further performance improvements, at
  745. least one of which (alias analysis) is not generally applicable to
  746. `f2c' (though `f2c' could presumably be changed to also take advantage
  747. of this new capability of the `gcc' back end, assuming this is made
  748. available in an upcoming release of `gcc').
  749.  
  750. 
  751. File: g77.info,  Node: Ease of Debugging,  Next: Character and Hollerith Constants,  Prev: Program Speed,  Up: Advantages Over f2c
  752.  
  753. Ease of Debugging
  754. -----------------
  755.  
  756.    Because `g77' compiles directly to assembler code like `gcc',
  757. instead of translating to an intermediate language (C) as does `f2c',
  758. support for debugging can be better for `g77' than `f2c'.
  759.  
  760.    However, although `g77' might be somewhat more "native" in terms of
  761. debugging support than `f2c' plus `gcc', there still are a lot of
  762. things "not quite right".  Many of the important ones should be
  763. resolved in the near future.
  764.  
  765.    For example, `g77' doesn't have to worry about reserved names like
  766. `f2c' does.  Given `FOR = WHILE', `f2c' must necessarily translate this
  767. to something *other* than `for = while;', because C reserves those
  768. words.
  769.  
  770.    However, `g77' does still uses things like an extra level of
  771. indirection for `ENTRY'-laden procedures--in this case, because the
  772. back end doesn't yet support multiple entry points.
  773.  
  774.    Another example is that, given
  775.  
  776.      COMMON A, B
  777.      EQUIVALENCE (B, C)
  778.  
  779. the `g77' user should be able to access the variables directly, by name,
  780. without having to traverse C-like structures and unions, while `f2c' is
  781. unlikely to ever offer this ability (due to limitations in the C
  782. language).
  783.  
  784.    However, due to apparent bugs in the back end, `g77' currently
  785. doesn't take advantage of this facility at all--it doesn't emit any
  786. debugging information for `COMMON' and `EQUIVALENCE' areas, other than
  787. information on the array of `char' it creates (and, in the case of
  788. local `EQUIVALENCE', names) for each such area.
  789.  
  790.    Yet another example is arrays.  `g77' represents them to the debugger
  791. using the same "dimensionality" as in the source code, while `f2c' must
  792. necessarily convert them all to one-dimensional arrays to fit into the
  793. confines of the C language.  However, the level of support offered by
  794. debuggers for interactive Fortran-style access to arrays as compiled by
  795. `g77' can vary widely.  In some cases, it can actually be an advantage
  796. that `f2c' converts everything to widely supported C semantics.
  797.  
  798.    In fairness, `g77' could do many of the things `f2c' does to get
  799. things working at least as well as `f2c'--for now, the developers
  800. prefer making `g77' work the way they think it is supposed to, and
  801. finding help improving the other products (the back end of `gcc';
  802. `gdb'; and so on) to get things working properly.
  803.  
  804. 
  805. File: g77.info,  Node: Character and Hollerith Constants,  Prev: Ease of Debugging,  Up: Advantages Over f2c
  806.  
  807. Character and Hollerith Constants
  808. ---------------------------------
  809.  
  810.    To avoid the extensive hassle that would be needed to avoid this,
  811. `f2c' uses C character constants to encode character and Hollerith
  812. constants.  That means a constant like `'HELLO'' is translated to
  813. `"hello"' in C, which further means that an extra null byte is present
  814. at the end of the constant.  This null byte is superfluous.
  815.  
  816.    `g77' does not generate such null bytes.  This represents significant
  817. savings of resources, such as on systems where `/dev/null' or
  818. `/dev/zero' represent bottlenecks in the systems' performance, because
  819. `g77' simply asks for fewer zeros from the operating system than `f2c'.
  820. (Avoiding spurious use of zero bytes, each byte typically have eight
  821. zero bits, also reduces the liabilities in case Microsoft's rumored
  822. patent on the digits 0 and 1 is upheld.)
  823.  
  824. 
  825. File: g77.info,  Node: Block Data and Libraries,  Next: Loops,  Prev: Advantages Over f2c,  Up: Collected Fortran Wisdom
  826.  
  827. Block Data and Libraries
  828. ========================
  829.  
  830.    To ensure that block data program units are linked, especially a
  831. concern when they are put into libraries, give each one a name (as in
  832. `BLOCK DATA FOO') and make sure there is an `EXTERNAL FOO' statement in
  833. every program unit that uses any common block initialized by the
  834. corresponding `BLOCK DATA'.  `g77' currently compiles a `BLOCK DATA' as
  835. if it were a `SUBROUTINE', that is, it generates an actual procedure
  836. having the appropriate name.  The procedure does nothing but return
  837. immediately if it happens to be called.  For `EXTERNAL FOO', where
  838. `FOO' is not otherwise referenced in the same program unit, `g77'
  839. assumes there exists a `BLOCK DATA FOO' in the program and ensures that
  840. by generating a reference to it so the linker will make sure it is
  841. present.  (Specifically, `g77' outputs in the data section a static
  842. pointer to the external name `FOO'.)
  843.  
  844.    The implementation `g77' currently uses to make this work is one of
  845. the few things not compatible with `f2c' as currently shipped.  `f2c'
  846. currently does nothing with `EXTERNAL FOO' except issue a warning that
  847. `FOO' is not otherwise referenced, and, for `BLOCK DATA FOO', `f2c'
  848. doesn't generate a dummy procedure with the name `FOO'.  The upshot is
  849. that you shouldn't mix `f2c' and `g77' in this particular case.  If you
  850. use `f2c' to compile `BLOCK DATA FOO', then any `g77'-compiled program
  851. unit that says `EXTERNAL FOO' will result in an unresolved reference
  852. when linked.  If you do the opposite, then `FOO' might not be linked in
  853. under various circumstances (such as when `FOO' is in a library, or
  854. you're using a "clever" linker--so clever, it produces a broken program
  855. with little or no warning by omitting initializations of global data
  856. because they are contained in unreferenced procedures).
  857.  
  858.    The changes you make to your code to make `g77' handle this
  859. situation, however, appear to be a widely portable way to handle it.
  860. That is, many systems permit it (as they should, since the FORTRAN 77
  861. standard permits `EXTERNAL FOO' when `FOO' is a block data program
  862. unit), and of the ones that might not link `BLOCK DATA FOO' under some
  863. circumstances, most of them appear to do so once `EXTERNAL FOO' is
  864. present in the appropriate program units.
  865.  
  866.    Here is the recommended approach to modifying a program containing a
  867. program unit such as the following:
  868.  
  869.      BLOCK DATA FOO
  870.      COMMON /VARS/ X, Y, Z
  871.      DATA X, Y, Z / 3., 4., 5. /
  872.      END
  873.  
  874. If the above program unit might be placed in a library module, then
  875. ensure that every program unit in every program that references that
  876. particular `COMMON' area uses the `EXTERNAL' statement to force the
  877. area to be initialized.
  878.  
  879.    For example, change a program unit that starts with
  880.  
  881.      INTEGER FUNCTION CURX()
  882.      COMMON /VARS/ X, Y, Z
  883.      CURX = X
  884.      END
  885.  
  886. so that it uses the `EXTERNAL' statement, as in:
  887.  
  888.      INTEGER FUNCTION CURX()
  889.      COMMON /VARS/ X, Y, Z
  890.      EXTERNAL FOO
  891.      CURX = X
  892.      END
  893.  
  894. That way, `CURX' is compiled by `g77' (and many other compilers) so
  895. that the linker knows it must include `FOO', the `BLOCK DATA' program
  896. unit that sets the initial values for the variables in `VAR', in the
  897. executable program.
  898.  
  899. 
  900. File: g77.info,  Node: Loops,  Next: Working Programs,  Prev: Block Data and Libraries,  Up: Collected Fortran Wisdom
  901.  
  902. Loops
  903. =====
  904.  
  905.    The meaning of a `DO' loop in Fortran is precisely specified in the
  906. Fortran standard...and is quite different from what many programmers
  907. might expect.
  908.  
  909.    In particular, Fortran iterative `DO' loops are implemented as if
  910. the number of trips through the loop is calculated *before* the loop is
  911. entered.
  912.  
  913.    The number of trips for a loop is calculated from the START, END,
  914. and INCREMENT values specified in a statement such as:
  915.  
  916.      DO ITER = START, END, INCREMENT
  917.  
  918. The trip count is evaluated using a fairly simple formula based on the
  919. three values following the `=' in the statement, and it is that trip
  920. count that is effectively decremented during each iteration of the loop.
  921. If, at the beginning of an iteration of the loop, the trip count is
  922. zero or negative, the loop terminates.  The per-loop-iteration
  923. modifications to ITER are not related to determining whether to
  924. terminate the loop.
  925.  
  926.    There are two important things to remember about the trip count:
  927.  
  928.    * It can be *negative*, in which case it is treated as if it was
  929.      zero--meaning the loop is not executed at all.
  930.  
  931.    * The type used to *calculate* the trip count is the same type as
  932.      ITER, but the final calculation, and thus the type of the trip
  933.      count itself, always is `INTEGER(KIND=1)'.
  934.  
  935.    These two items mean that there are loops that cannot be written in
  936. straightforward fashion using the Fortran `DO'.
  937.  
  938.    For example, on a system with the canonical 32-bit two's-complement
  939. implementation of `INTEGER(KIND=1)', the following loop will not work:
  940.  
  941.      DO I = -2000000000, 2000000000
  942.  
  943. Although the START and END values are well within the range of
  944. `INTEGER(KIND=1)', the *trip count* is not.  The expected trip count is
  945. 40000000001, which is outside the range of `INTEGER(KIND=1)' on many
  946. systems.
  947.  
  948.    Instead, the above loop should be constructed this way:
  949.  
  950.      I = -2000000000
  951.      DO
  952.        IF (I .GT. 2000000000) EXIT
  953.        ...
  954.        I = I + 1
  955.      END DO
  956.  
  957. The simple `DO' construct and the `EXIT' statement (used to leave the
  958. innermost loop) are F90 features that `g77' supports.
  959.  
  960.    Some Fortran compilers have buggy implementations of `DO', in that
  961. they don't follow the standard.  They implement `DO' as a
  962. straightforward translation to what, in C, would be a `for' statement.
  963. Instead of creating a temporary variable to hold the trip count as
  964. calculated at run time, these compilers use the iteration variable ITER
  965. to control whether the loop continues at each iteration.
  966.  
  967.    The bug in such an implementation shows up when the trip count is
  968. within the range of the type of ITER, but the magnitude of `ABS(END) +
  969. ABS(INCR)' exceeds that range.  For example:
  970.  
  971.      DO I = 2147483600, 2147483647
  972.  
  973. A loop started by the above statement will work as implemented by
  974. `g77', but the use, by some compilers, of a more C-like implementation
  975. akin to
  976.  
  977.      for (i = 2147483600; i <= 2147483647; ++i)
  978.  
  979. produces a loop that does not terminate, because `i' can never be
  980. greater than 2147483647, since incrementing it beyond that value
  981. overflows `i', setting it to -2147483648.  This is a large, negative
  982. number that still is less than 2147483647.
  983.  
  984.    Another example of unexpected behavior of `DO' involves using a
  985. nonintegral iteration variable ITER, that is, a `REAL' variable.
  986. Consider the following program:
  987.  
  988.            DATA BEGIN, END, STEP /.1, .31, .007/
  989.            DO 10 R = BEGIN, END, STEP
  990.               IF (R .GT. END) PRINT *, R, ' .GT. ', END, '!!'
  991.               PRINT *,R
  992.      10    CONTINUE
  993.            PRINT *,'LAST = ',R
  994.            IF (R .LE. END) PRINT *, R, ' .LE. ', END, '!!'
  995.            END
  996.  
  997. A C-like view of `DO' would hold that the two "exclamatory" `PRINT'
  998. statements are never executed.  However, this is the output of running
  999. the above program as compiled by `g77' on a GNU/Linux ix86 system:
  1000.  
  1001.       .100000001
  1002.       .107000001
  1003.       .114
  1004.       .120999999
  1005.       ...
  1006.       .289000005
  1007.       .296000004
  1008.       .303000003
  1009.      LAST =   .310000002
  1010.       .310000002 .LE.   .310000002!!
  1011.  
  1012.    Note that one of the two checks in the program turned up an apparent
  1013. violation of the programmer's expectation--yet, the loop is correctly
  1014. implemented by `g77', in that it has 30 iterations.  This trip count of
  1015. 30 is correct when evaluated using the floating-point representations
  1016. for the BEGIN, END, and INCR values (.1, .31, .007) on GNU/Linux ix86
  1017. are used.  On other systems, an apparently more accurate trip count of
  1018. 31 might result, but, nevertheless, `g77' is faithfully following the
  1019. Fortran standard, and the result is not what the author of the sample
  1020. program above apparently expected.  (Such other systems might, for
  1021. different values in the `DATA' statement, violate the other
  1022. programmer's expectation, for example.)
  1023.  
  1024.    Due to this combination of imprecise representation of
  1025. floating-point values and the often-misunderstood interpretation of
  1026. `DO' by standard-conforming compilers such as `g77', use of `DO' loops
  1027. with `REAL' iteration variables is not recommended.  Such use can be
  1028. caught by specifying `-Wsurprising'.  *Note Warning Options::, for more
  1029. information on this option.
  1030.  
  1031. 
  1032. File: g77.info,  Node: Working Programs,  Next: Overly Convenient Options,  Prev: Loops,  Up: Collected Fortran Wisdom
  1033.  
  1034. Working Programs
  1035. ================
  1036.  
  1037.    Getting Fortran programs to work in the first place can be quite a
  1038. challenge--even when the programs already work on other systems, or
  1039. when using other compilers.
  1040.  
  1041.    `g77' offers some facilities that might be useful for tracking down
  1042. bugs in such programs.
  1043.  
  1044. * Menu:
  1045.  
  1046. * Not My Type::
  1047. * Variables Assumed To Be Zero::
  1048. * Variables Assumed To Be Saved::
  1049. * Unwanted Variables::
  1050. * Unused Arguments::
  1051. * Surprising Interpretations of Code::
  1052. * Aliasing Assumed To Work::
  1053. * Output Assumed To Flush::
  1054. * Large File Unit Numbers::
  1055. * Floating-point precision::
  1056. * Inconsistent Calling Sequences::
  1057.  
  1058. 
  1059. File: g77.info,  Node: Not My Type,  Next: Variables Assumed To Be Zero,  Up: Working Programs
  1060.  
  1061. Not My Type
  1062. -----------
  1063.  
  1064.    A fruitful source of bugs in Fortran source code is use, or mis-use,
  1065. of Fortran's implicit-typing feature, whereby the type of a variable,
  1066. array, or function is determined by the first character of its name.
  1067.  
  1068.    Simple cases of this include statements like `LOGX=9.227', without a
  1069. statement such as `REAL LOGX'.  In this case, `LOGX' is implicitly
  1070. given `INTEGER(KIND=1)' type, with the result of the assignment being
  1071. that it is given the value `9'.
  1072.  
  1073.    More involved cases include a function that is defined starting with
  1074. a statement like `DOUBLE PRECISION FUNCTION IPS(...)'.  Any caller of
  1075. this function that does not also declare `IPS' as type `DOUBLE
  1076. PRECISION' (or, in GNU Fortran, `REAL(KIND=2)') is likely to assume it
  1077. returns `INTEGER', or some other type, leading to invalid results or
  1078. even program crashes.
  1079.  
  1080.    The `-Wimplicit' option might catch failures to properly specify the
  1081. types of variables, arrays, and functions in the code.
  1082.  
  1083.    However, in code that makes heavy use of Fortran's implicit-typing
  1084. facility, this option might produce so many warnings about cases that
  1085. are working, it would be hard to find the one or two that represent
  1086. bugs.  This is why so many experienced Fortran programmers strongly
  1087. recommend widespread use of the `IMPLICIT NONE' statement, despite it
  1088. not being standard FORTRAN 77, to completely turn off implicit typing.
  1089. (`g77' supports `IMPLICIT NONE', as do almost all FORTRAN 77 compilers.)
  1090.  
  1091.    Note that `-Wimplicit' catches only implicit typing of *names*.  It
  1092. does not catch implicit typing of expressions such as `X**(2/3)'.  Such
  1093. expressions can be buggy as well--in fact, `X**(2/3)' is equivalent to
  1094. `X**0', due to the way Fortran expressions are given types and then
  1095. evaluated.  (In this particular case, the programmer probably wanted
  1096. `X**(2./3.)'.)
  1097.  
  1098. 
  1099. File: g77.info,  Node: Variables Assumed To Be Zero,  Next: Variables Assumed To Be Saved,  Prev: Not My Type,  Up: Working Programs
  1100.  
  1101. Variables Assumed To Be Zero
  1102. ----------------------------
  1103.  
  1104.    Many Fortran programs were developed on systems that provided
  1105. automatic initialization of all, or some, variables and arrays to zero.
  1106. As a result, many of these programs depend, sometimes inadvertently, on
  1107. this behavior, though to do so violates the Fortran standards.
  1108.  
  1109.    You can ask `g77' for this behavior by specifying the
  1110. `-finit-local-zero' option when compiling Fortran code.  (You might
  1111. want to specify `-fno-automatic' as well, to avoid code-size inflation
  1112. for non-optimized compilations.)
  1113.  
  1114.    Note that a program that works better when compiled with the
  1115. `-finit-local-zero' option is almost certainly depending on a
  1116. particular system's, or compiler's, tendency to initialize some
  1117. variables to zero.  It might be worthwhile finding such cases and
  1118. fixing them, using techniques such as compiling with the `-O
  1119. -Wuninitialized' options using `g77'.
  1120.  
  1121. 
  1122. File: g77.info,  Node: Variables Assumed To Be Saved,  Next: Unwanted Variables,  Prev: Variables Assumed To Be Zero,  Up: Working Programs
  1123.  
  1124. Variables Assumed To Be Saved
  1125. -----------------------------
  1126.  
  1127.    Many Fortran programs were developed on systems that saved the
  1128. values of all, or some, variables and arrays across procedure calls.
  1129. As a result, many of these programs depend, sometimes inadvertently, on
  1130. being able to assign a value to a variable, perform a `RETURN' to a
  1131. calling procedure, and, upon subsequent invocation, reference the
  1132. previously assigned variable to obtain the value.
  1133.  
  1134.    They expect this despite not using the `SAVE' statement to specify
  1135. that the value in a variable is expected to survive procedure returns
  1136. and calls.  Depending on variables and arrays to retain values across
  1137. procedure calls without using `SAVE' to require it violates the Fortran
  1138. standards.
  1139.  
  1140.    You can ask `g77' to assume `SAVE' is specified for all relevant
  1141. (local) variables and arrays by using the `-fno-automatic' option.
  1142.  
  1143.    Note that a program that works better when compiled with the
  1144. `-fno-automatic' option is almost certainly depending on not having to
  1145. use the `SAVE' statement as required by the Fortran standard.  It might
  1146. be worthwhile finding such cases and fixing them, using techniques such
  1147. as compiling with the `-O -Wuninitialized' options using `g77'.
  1148.  
  1149. 
  1150. File: g77.info,  Node: Unwanted Variables,  Next: Unused Arguments,  Prev: Variables Assumed To Be Saved,  Up: Working Programs
  1151.  
  1152. Unwanted Variables
  1153. ------------------
  1154.  
  1155.    The `-Wunused' option can find bugs involving implicit typing,
  1156. sometimes more easily than using `-Wimplicit' in code that makes heavy
  1157. use of implicit typing.  An unused variable or array might indicate
  1158. that the spelling for its declaration is different from that of its
  1159. intended uses.
  1160.  
  1161.    Other than cases involving typos, unused variables rarely indicate
  1162. actual bugs in a program.  However, investigating such cases thoroughly
  1163. has, on occasion, led to the discovery of code that had not been
  1164. completely written--where the programmer wrote declarations as needed
  1165. for the whole algorithm, wrote some or even most of the code for that
  1166. algorithm, then got distracted and forgot that the job was not complete.
  1167.  
  1168. 
  1169. File: g77.info,  Node: Unused Arguments,  Next: Surprising Interpretations of Code,  Prev: Unwanted Variables,  Up: Working Programs
  1170.  
  1171. Unused Arguments
  1172. ----------------
  1173.  
  1174.    As with unused variables, It is possible that unused arguments to a
  1175. procedure might indicate a bug.  Compile with `-W -Wunused' option to
  1176. catch cases of unused arguments.
  1177.  
  1178.    Note that `-W' also enables warnings regarding overflow of
  1179. floating-point constants under certain circumstances.
  1180.  
  1181.